<template>
  <div class="goods-info">
    <Swipe :itemList="GoodInfoList.album"></Swipe>
    <!-- 商品购买区域 -->
    <div class="mui-card">
      <div class="mui-card-header">{{ GoodInfoList.name }}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            定价：<span>¥{{ GoodInfoList.price }}</span>
          </p>
          <div class="buy-count">
            <numbox @count="getcountchange" :max='GoodInfoList.num' :initcount="1" :goodid="GoodInfoList.id"></numbox>
          </div>

          <div v-if="GoodInfoList.num">
            <p class="go-buy">
              <mt-button type="primary" size="small">立即购买</mt-button>
              <mt-button type="danger" size="small" @click="addcar()">加入购物车</mt-button>
            </p>
          </div>
          <div v-else>该商品暂时无货</div>
        </div>
      </div>
    </div>
    <!-- 商品参数区域 -->
    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>购买{{sycount}}件</p>
          <p>商品卖点：{{ GoodInfoList.sell_point }}</p>
          <p>库存情况：{{ GoodInfoList.num }}件</p>
          <p>上架时间：{{ GoodInfoList.create_time }}</p>
        </div>
      </div>
      <div class="mui-card-header">商品详情</div>
      <div class="good-desc">
        <div class="content" v-html="GoodInfoList.content"></div>
      </div>
    </div>
  </div>

</template>

<script>
import Swipe from '../../components/Swipe.vue'
import numbox from '../../components/numbox.vue'
export default {
  props: ['id'],
  components: { Swipe, numbox },
  data () {
    return {
      GoodInfoList: [],
      // 购买数量
      sycount: null
    }
  },
  created () {
    this.GoodInfo()
  },
  methods: {
    addcar () {
      this.$store.commit('shopcar/addShopcar',
        { id: parseInt(this.id), count: this.sycount, selected: true })
      this.$toast('加入购物车成功')
    },
    getcountchange (newval) {
      this.sycount = newval.count
    },
    GoodInfo () {
      this.$indicator.open({ text: '加载中' })
      this.$http
        .get('goodsinfo', { params: { id: this.id } })
        .then(res => {
          this.$indicator.close()
          if (res.data.code === 1) {
            // 成功
            if (res.data.data !== null) {
              this.GoodInfoList = res.data.data
            }
          } else {
            this.$toast(this.data.msg)
          }
          // console.log(res.data)
        })
        .catch(() => {
          this.$toast('服务器异常')
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-info {
  background: #f1f1ff;
  overflow: hidden;
  .price {
    span {
      color: red;
      font-size: 14px;
      font-weight: bold;
    }
  }
  .go-buy {
    display: flex;
    margin: 10px 0 0px;
    justify-content: center;
    button {
      margin: 0 5px;
    }
  }
  .good-desc {
    background: #fff;
    padding: 5px;
    h3 {
      font-size: 16px;
      color: #226aff;
      text-align: center;
      margin: 15px 0;
    }
    .content {
      font-size: 14px;
      line-height: 28px;
      img {
        width: 100%;
      }
    }
  }
}
</style>
